/*
 * Copyright (C) 2013 TopCoder Inc., All Rights Reserved.
 */
package cn.itcast.heima;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @author TCSASSEMBLER
 * @version 1.0 ()
 * @since 1.0
 */
public class ThreadScoopeShareData {
	
	private static int data = 0;
	private static Map<Thread, Integer> threadData = new HashMap<Thread, Integer>();
	/**
	 *<p></p>
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for (int i = 0; i < 2; i++)
		new Thread(
				new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						int data = new Random().nextInt();
						System.out.println(Thread.currentThread().getName()
								+ "has put data: " + data);
						threadData.put(Thread.currentThread(), data);
						new A().get();
						new B().get();
					}
				}
		).start();
	}
	
	static class A {
		public void get() {
			int data = threadData.get(Thread.currentThread());
			System.out.println("A from " + Thread.currentThread().getName()
					+ "get data: " + data);
			
		}
	}
	
	static class B {
		public void get() {
			int data = threadData.get(Thread.currentThread());
			System.out.println("B from " + Thread.currentThread().getName()
					+ "get data: " + data);
			
		}
	}

}
